part of base_package;

class DialogFactory {
  /// 调取拍照，相册选择，视频录制，call:filePathList<List>,照片是1/视频是2
  static cameraAndGallery(BuildContext context, Function call,
      {int? type, int maxAssets = 9}) {
    showModalBottomSheet(
        context: context,
        builder: (builder) {
          return SafeArea(
            child: Container(
              height: type == null ? 200 : 100,
              color: Colors.transparent,
              child: Container(
                decoration: const BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(10.0),
                        topRight: Radius.circular(10.0))),
                child: Column(
                  children: [
                    (type == null || type == 1)
                        ? InkWell(
                            onTap: () async {
                              PickedFile? xFile =
                                  await FileUtil.getImageOrVideo(context, 0);
                              Navigator.pop(context);
                              call([xFile?.path], 1);
                              xFile = null;
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: double.infinity,
                              height: 50,
                              child: const Text(
                                "拍摄照片",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  fontSize: 18,
                                  color: Color(0xFF567DF4),
                                ),
                              ),
                            ),
                          )
                        : Container(),
                    (type == null || type == 2)
                        ? InkWell(
                            onTap: () async {
                              PickedFile? xFile =
                                  await FileUtil.getImageOrVideo(context, 2);
                              Navigator.pop(context);
                              call([xFile?.path], 2);
                              xFile = null;
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: double.infinity,
                              height: 50,
                              child: const Text(
                                "拍摄视频",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  fontSize: 18,
                                  color: Color(0xFF567DF4),
                                ),
                              ),
                            ),
                          )
                        : Container(),
                    (type == null || type == 1)
                        ? InkWell(
                            onTap: () async {
                              final List<AssetEntity> assetEntityList =
                                  await AssetPicker.pickAssets(
                                        context,
                                        pickerConfig: AssetPickerConfig(
                                          maxAssets: maxAssets,
                                          gridCount: 4,
                                          requestType: RequestType.image,
                                        ),
                                      ) ??
                                      [];
                              List filePathList = [];
                              for (AssetEntity assetEntity in assetEntityList) {
                                File? file = await assetEntity.file;
                                filePathList.add(file?.path);
                              }
                              Navigator.pop(context);
                              call(filePathList, 1);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: double.infinity,
                              height: 50,
                              child: const Text(
                                "选取图片",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  fontSize: 18,
                                  color: Color(0xFF567DF4),
                                ),
                              ),
                            ),
                          )
                        : Container(),
                    (type == null || type == 2)
                        ? InkWell(
                            onTap: () async {
                              final List<AssetEntity> assetEntityList =
                                  await AssetPicker.pickAssets(
                                        context,
                                        pickerConfig: AssetPickerConfig(
                                          maxAssets: maxAssets,
                                          gridCount: 4,
                                          requestType: RequestType.video,
                                        ),
                                      ) ??
                                      [];
                              List filePathList = [];
                              for (AssetEntity assetEntity in assetEntityList) {
                                File? file = await assetEntity.file;
                                filePathList.add(file?.path);
                              }
                              Navigator.pop(context);
                              call(filePathList, 2);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              width: double.infinity,
                              height: 50,
                              child: const Text(
                                "选取视频",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  fontSize: 18,
                                  color: Color(0xFF567DF4),
                                ),
                              ),
                            ),
                          )
                        : Container(),
                  ],
                ),
              ),
            ),
          );
        });
  }

  /// 字符串选择器
  static pickerS(BuildContext context, List<String> dataList,
      {int initIndex = 0,
      required Function onConfirm,
      required Function onCancel}) {
    if (dataList.isEmpty) {
      '没有数据'.toString().toast();
      return;
    }
    showCupertinoModalPopup(
        context: context,
        builder: (cxt) {
          String confirmData = dataList[initIndex];
          int mIndex = initIndex;
          List<Widget> itemList = [];
          for (String data in dataList) {
            itemList.add(Text(data));
          }
          return SafeArea(
            child: Column(
              children: [
                Expanded(child: Container()),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onCancel(),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 15, bottom: 5, right: 5),
                          child: const Text(
                            '取消',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onConfirm(confirmData, mIndex),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 5, bottom: 5, right: 15),
                          child: const Text(
                            '确定',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                SizedBox(
                  height: 200,
                  child: CupertinoPicker(
                    scrollController:
                        FixedExtentScrollController(initialItem: initIndex),
                    backgroundColor: Colors.white,
                    //选择器背景色
                    itemExtent: 30,
                    //item的高度
                    onSelectedItemChanged: (index) {
                      mIndex = index;
                      confirmData = dataList[index];
                    },
                    children: itemList,
                  ),
                ),
              ],
            ),
          );
        });
  }

  /// Map选择器
  static pickerMap(BuildContext context, List<dynamic> dataList, String name,
      {int initialItem = 0,
      required Function onConfirm,
      required Function onCancel}) {
    if (dataList.isEmpty) {
      '没有数据'.toString().toast();
      return;
    }
    showCupertinoModalPopup(
        context: context,
        builder: (cxt) {
          Map confirmData = dataList[0];
          int mIndex = 0;
          List<Widget> itemList = [];
          for (Map data in dataList) {
            itemList.add(Text(data[name]));
          }
          return SafeArea(
            child: Column(
              children: [
                Expanded(child: Container()),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onCancel(),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 15, bottom: 5, right: 5),
                          child: const Text(
                            '取消',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onConfirm(confirmData, mIndex),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 5, bottom: 5, right: 15),
                          child: const Text(
                            '确定',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                SizedBox(
                  height: 200,
                  child: CupertinoPicker(
                    scrollController:
                        FixedExtentScrollController(initialItem: initialItem),
                    backgroundColor: Colors.white,
                    //选择器背景色
                    itemExtent: 30,
                    //item的高度
                    onSelectedItemChanged: (index) {
                      mIndex = index;
                      confirmData = dataList[index];
                    },
                    children: itemList,
                  ),
                ),
              ],
            ),
          );
        });
  }

  /// searchMap选择器
  static pickerSearchMap(
      BuildContext context, List<dynamic> dataList, String name,
      {required Function onConfirm, required Function onCancel}) {
    if (dataList.isEmpty) {
      '没有数据'.toString().toast();
      return;
    }
    showCupertinoModalPopup(
        context: context,
        builder: (cxt) {
          Map confirmData = dataList[0];
          int mIndex = 0;
          List<dynamic> tempList = [];
          for (Map data in dataList) {
            tempList.add(data);
          }
          return SafeArea(
            child: StatefulBuilder(builder: (context, state) {
              return Column(
                children: [
                  Expanded(child: Container()),
                  Container(
                    padding: const EdgeInsets.only(left: 10, right: 10),
                    color: Colors.white,
                    child: Stack(
                      alignment: Alignment.center,
                      children: [
                        Positioned(
                          child: Container(
                            height: 40,
                            decoration: BoxDecoration(
                              color: Colors.white,
                              //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                              borderRadius:
                                  const BorderRadius.all(Radius.circular(100)),
                              //设置四周边框
                              border: Border.all(width: 1, color: Colors.black),
                            ),
                          ),
                        ),
                        Positioned(
                          child: Row(
                            children: [
                              Expanded(
                                child: Container(
                                  padding:
                                      const EdgeInsets.only(left: 10, top: 5),
                                  height: 60,
                                  child: TextField(
                                    decoration: const InputDecoration(
                                      border: InputBorder.none,
                                      hintText: "请输入关键词",
                                      hintStyle: TextStyle(
                                        color: Color(0x66333333),
                                        fontSize: 14,
                                      ),
                                    ),
                                    onChanged: (text) {
                                      state(() {
                                        tempList.clear();
                                        if (text.isEmpty) {
                                          for (Map data in dataList) {
                                            tempList.add(data);
                                          }
                                        } else {
                                          for (Map data in dataList) {
                                            if (data[name].contains(text)) {
                                              tempList.add(data);
                                            }
                                          }
                                        }
                                      });
                                    },
                                  ),
                                ),
                              ),
                              Container(width: 10),
                              InkWell(
                                onTap: () {},
                                child: const Icon(Icons.search_outlined),
                              ),
                              Container(width: 10),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    height: 400,
                    child: MediaQuery.removePadding(
                      context: context,
                      removeTop: true,
                      child: ListView.separated(
                        itemCount: tempList.length,
                        itemBuilder: (BuildContext context, int index) {
                          return InkWell(
                            child: Container(
                              alignment: Alignment.center,
                              padding: const EdgeInsets.all(5),
                              child: Text(
                                tempList[index][name],
                                style: const TextStyle(
                                    color: Colors.black, fontSize: 18),
                              ),
                            ),
                            onTap: () {
                              Navigator.pop(cxt);
                              mIndex = index;
                              confirmData = tempList[index];
                              onConfirm(confirmData, mIndex);
                            },
                          );
                        },
                        separatorBuilder: (BuildContext context, int index) {
                          return const Divider(
                              height: 1, color: Color(0x33000000));
                        },
                      ),
                    ),
                  ),
                ],
              );
            }),
          );
        });
  }

  /// 跳转到地图
  static goMap(BuildContext context, String longitude, String latitude) {
    showModalBottomSheet(
        context: context,
        builder: (builder) {
          return SafeArea(
            child: Container(
              height: 100,
              color: Colors.transparent,
              //could change this to Color(0xFF737373),
              //so you don't have to change MaterialApp canvasColor
              child: Container(
                decoration: const BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(10.0),
                        topRight: Radius.circular(10.0))),
                child: Column(
                  children: [
                    InkWell(
                      onTap: () => {
                        _gotoBaiduMap(longitude, latitude),
                      },
                      child: Container(
                        alignment: Alignment.center,
                        width: double.infinity,
                        height: 50,
                        child: const Text(
                          "百度地图",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            fontSize: 18,
                            color: Color(0xFF567DF4),
                          ),
                        ),
                      ),
                    ),
                    InkWell(
                      onTap: () => {
                        _gotoAMap(longitude, latitude),
                      },
                      child: Container(
                        height: 50,
                        alignment: Alignment.center,
                        width: double.infinity,
                        child: const Text(
                          "高德地图",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            fontSize: 18,
                            color: Color(0xFF567DF4),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          );
        });
  }

  /// 高德地图
  static Future<bool> _gotoAMap(longitude, latitude) async {
    var url =
        '${Platform.isAndroid ? 'android' : 'ios'}amap://navi?sourceApplication=amap&lat=$latitude&lon=$longitude&dev=0&style=2';

    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      EasyLoading.showToast('未检测到高德地图~');
      return false;
    }

    await launch(url);

    return canLaunchUrl;
  }

  /// 百度地图
  static Future<bool> _gotoBaiduMap(longitude, latitude) async {
    var url =
        'baidumap://map/direction?destination=$latitude,$longitude&coord_type=bd09ll&mode=driving';

    bool canLaunchUrl = await canLaunch(url);

    if (!canLaunchUrl) {
      EasyLoading.showToast('未检测到百度地图~');
      return false;
    }

    await launch(url);

    return canLaunchUrl;
  }

  /// 日期选择器
  static dateSelect(BuildContext context,
      {bool isTime1 = true,
      DateTime? maxTime,
      DateTime? minTime,
      DateTime? currentTime,
      required Function onTime}) {
    DateTime dateTime = DateTime.now();
    DateTime dateTime1 = DateTime(2000, 1, 1);
    if (isTime1) {
      DatePicker.showDatePicker(context,
          showTitleActions: true,
          minTime: minTime ?? dateTime1,
          maxTime: maxTime ?? dateTime,
          currentTime: maxTime == null ? dateTime : currentTime,
          onConfirm: (date) {
        onTime(date.toString().split(' ')[0]);
      }, locale: LocaleType.zh);
    } else {
      String time = "";
      DatePicker.showDatePicker(context,
          title: "选择开始时间",
          showTitleActions: true,
          minTime: minTime ?? dateTime1,
          maxTime: maxTime ?? dateTime,
          currentTime: maxTime == null ? dateTime : currentTime,
          onConfirm: (date) {
        time += date.toString().split(' ')[0];
        DatePicker.showDatePicker(context,
            title: "选择结束时间",
            showTitleActions: true,
            minTime: minTime ?? dateTime1,
            maxTime: maxTime ?? dateTime,
            currentTime: maxTime == null ? dateTime : currentTime,
            onConfirm: (date) {
          time += " 至 ${date.toString().split(' ')[0]}";
          onTime(time);
        }, locale: LocaleType.zh);
      }, locale: LocaleType.zh);
    }
  }

  /// 日期时间选择器
  static dateTimeSelect(BuildContext context,
      {bool isTime1 = true,
      DateTime? maxTime,
      DateTime? minTime,
      DateTime? currentTime,
      bool isShowMinute = true,
      required Function onTime}) {
    DateTime dateTime = DateTime.now();
    DateTime dateTime1 = DateTime(2000, 1, 1);
    if (isTime1) {
      DatePicker.showDateTimePicker(context,
          showTitleActions: true,
          minTime: minTime == null ? dateTime1 : minTime,
          maxTime: maxTime == null ? dateTime : maxTime,
          currentTime: maxTime == null ? dateTime : currentTime,
          isShowMinute: isShowMinute, onConfirm: (date) {
        onTime(date.toString().split('.')[0]);
      }, locale: LocaleType.zh);
    } else {
      String time = "";
      DatePicker.showDateTimePicker(context,
          title: "选择开始时间",
          showTitleActions: true,
          minTime: minTime == null ? dateTime1 : minTime,
          maxTime: maxTime == null ? dateTime : maxTime,
          currentTime: maxTime == null ? dateTime : currentTime,
          isShowMinute: isShowMinute, onConfirm: (date) {
        time += date.toString().split('.')[0];
        DatePicker.showDateTimePicker(context,
            title: "选择结束时间",
            showTitleActions: true,
            minTime: minTime == null ? dateTime1 : minTime,
            maxTime: dateTime,
            currentTime: maxTime == null ? dateTime : currentTime,
            isShowMinute: isShowMinute, onConfirm: (date) {
          time += " 至 ${date.toString().split('.')[0]}";
          onTime(time);
        }, locale: LocaleType.zh);
      }, locale: LocaleType.zh);
    }
  }

  /// 年月选择器
  static pickerYearMonth(BuildContext context,
      {String? currentYearMonth,
      required Function onConfirm,
      required Function onCancel}) {
    List yearList = [];
    List monthList = [];
    for (int i = 0; i < 20; i++) {
      yearList.add('${DateTime.now().year - i}');
      if (i < 12) {
        String month = '${1 + i}';
        if (month.length == 1) month = '0$month';
        monthList.add(month);
      }
    }
    int yearIndex = 0;
    int monthIndex = 0;
    if (currentYearMonth != null) {
      List split = currentYearMonth.split('-');
      yearIndex = yearList.indexOf(split[0]);
      monthIndex = monthList.indexOf(split[1]);
    }
    showCupertinoModalPopup(
        context: context,
        builder: (cxt) {
          String year = '${yearList[yearIndex]}';
          String month = '${monthList[monthIndex]}';
          List<Widget> yearItemList = [];
          List<Widget> monthItemList = [];
          for (String data in yearList) {
            yearItemList.add(Text(data));
          }
          for (String data in monthList) {
            monthItemList.add(Text(data));
          }
          return SafeArea(
            child: Column(
              children: [
                Expanded(child: Container()),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onCancel(),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 15, bottom: 5, right: 5),
                          child: const Text(
                            '取消',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onConfirm('$year-$month'),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 5, bottom: 5, right: 15),
                          child: const Text(
                            '确定',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                Row(
                  children: [
                    Expanded(
                      child: SizedBox(
                        height: 200,
                        child: CupertinoPicker(
                          scrollController: FixedExtentScrollController(
                              initialItem: yearIndex),
                          backgroundColor: Colors.white, //选择器背景色
                          itemExtent: 30, //item的高度
                          onSelectedItemChanged: (index) {
                            year = yearList[index];
                          },
                          children: yearItemList,
                        ),
                      ),
                    ),
                    Expanded(
                      child: SizedBox(
                        height: 200,
                        child: CupertinoPicker(
                          scrollController: FixedExtentScrollController(
                              initialItem: monthIndex),
                          backgroundColor: Colors.white, //选择器背景色
                          itemExtent: 30, //item的高度
                          onSelectedItemChanged: (index) {
                            month = monthList[index];
                          },
                          children: monthItemList,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          );
        });
  }

  /// 年选择器
  static pickerYear(BuildContext context,
      {String? currentYear,
      required Function onConfirm,
      required Function onCancel}) {
    List yearList = [];
    for (int i = 0; i < 20; i++) {
      yearList.add('${DateTime.now().year - i}');
    }
    int yearIndex = 0;
    if (currentYear != null) {
      yearIndex = yearList.indexOf(currentYear);
    }
    showCupertinoModalPopup(
        context: context,
        builder: (cxt) {
          String year = '${yearList[yearIndex]}';
          List<Widget> yearItemList = [];
          List<Widget> monthItemList = [];
          for (String data in yearList) {
            yearItemList.add(Text(data));
          }
          return SafeArea(
            child: Column(
              children: [
                Expanded(child: Container()),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onCancel(),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 15, bottom: 5, right: 5),
                          child: const Text(
                            '取消',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () => {
                          Navigator.pop(cxt),
                          onConfirm(year),
                        },
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.only(
                              top: 5, left: 5, bottom: 5, right: 15),
                          child: const Text(
                            '确定',
                            style: TextStyle(color: Colors.black, fontSize: 18),
                          ),
                        ),
                      ),
                    ],
                  ),
                  color: Colors.white,
                ),
                SizedBox(
                  height: 200,
                  child: CupertinoPicker(
                    scrollController:
                        FixedExtentScrollController(initialItem: yearIndex),
                    backgroundColor: Colors.white, //选择器背景色
                    itemExtent: 30, //item的高度
                    onSelectedItemChanged: (index) {
                      year = yearList[index];
                    },
                    children: yearItemList,
                  ),
                ),
              ],
            ),
          );
        });
  }

  /// 日期选择器-横向
  static dateSelectH(BuildContext context,
      {bool isTime1 = true,
      DateTime? maxTime,
      DateTime? minTime,
      DateTime? currentTime,
      required Function onTime}) {
    DateTime dateTime = DateTime.now();
    DateTime dateTime1 = DateTime(2000, 1, 1);
    DatePickerH.showDatePicker(context,
        showTitleActions: true,
        minTime: minTime ?? dateTime1,
        maxTime: maxTime ?? dateTime,
        currentTime: maxTime == null ? dateTime : currentTime,
        onConfirm: (date) {
      onTime(date.toString().split(' ')[0]);
    }, locale: LocaleType.zh);
  }

  /// 年月选择器-横向
  static pickerYearMonthH(BuildContext context,
      {String? currentYearMonth,
      required Function onConfirm,
      required Function onCancel}) {
    List yearList = [];
    List monthList = [];
    for (int i = 0; i < 20; i++) {
      yearList.add('${DateTime.now().year - i}');
      if (i < 12) {
        String month = '${1 + i}';
        if (month.length == 1) month = '0$month';
        monthList.add(month);
      }
    }
    int yearIndex = 0;
    int monthIndex = 0;
    if (currentYearMonth != null) {
      List split = currentYearMonth.split('-');
      yearIndex = yearList.indexOf(split[0]);
      monthIndex = monthList.indexOf(split[1]);
    }
    showCupertinoModalPopupH(
        context: context,
        builder: (cxt) {
          String year = '${yearList[yearIndex]}';
          String month = '${monthList[monthIndex]}';
          List<Widget> yearItemList = [];
          List<Widget> monthItemList = [];
          for (String data in yearList) {
            yearItemList.add(Text(data));
          }
          for (String data in monthList) {
            monthItemList.add(Text(data));
          }
          EdgeInsets padding = MediaQuery.of(context).padding;
          return RotatedBox(
            quarterTurns: 1,
            child: Container(
              margin: EdgeInsets.only(left: padding.top, right: padding.bottom),
              child: Column(
                children: [
                  Expanded(child: Container()),
                  Container(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        InkWell(
                          onTap: () => {
                            Navigator.pop(cxt),
                            onCancel(),
                          },
                          child: Container(
                            color: Colors.white,
                            padding: const EdgeInsets.only(
                                top: 5, left: 15, bottom: 5, right: 5),
                            child: const Text(
                              '取消',
                              style:
                                  TextStyle(color: Colors.black, fontSize: 18),
                            ),
                          ),
                        ),
                        InkWell(
                          onTap: () => {
                            Navigator.pop(cxt),
                            onConfirm('$year-$month'),
                          },
                          child: Container(
                            color: Colors.white,
                            padding: const EdgeInsets.only(
                                top: 5, left: 5, bottom: 5, right: 15),
                            child: const Text(
                              '确定',
                              style:
                                  TextStyle(color: Colors.black, fontSize: 18),
                            ),
                          ),
                        ),
                      ],
                    ),
                    color: Colors.white,
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: SizedBox(
                          height: 200,
                          child: CupertinoPicker(
                            scrollController: FixedExtentScrollController(
                                initialItem: yearIndex),
                            backgroundColor: Colors.white, //选择器背景色
                            itemExtent: 30, //item的高度
                            onSelectedItemChanged: (index) {
                              year = yearList[index];
                            },
                            children: yearItemList,
                          ),
                        ),
                      ),
                      Expanded(
                        child: SizedBox(
                          height: 200,
                          child: CupertinoPicker(
                            scrollController: FixedExtentScrollController(
                                initialItem: monthIndex),
                            backgroundColor: Colors.white, //选择器背景色
                            itemExtent: 30, //item的高度
                            onSelectedItemChanged: (index) {
                              month = monthList[index];
                            },
                            children: monthItemList,
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          );
        });
  }

  /// 年选择器-横向
  static pickerYearH(BuildContext context,
      {String? currentYear,
      required Function onConfirm,
      required Function onCancel}) {
    List yearList = [];
    for (int i = 0; i < 20; i++) {
      yearList.add('${DateTime.now().year - i}');
    }
    int yearIndex = 0;
    if (currentYear != null) {
      yearIndex = yearList.indexOf(currentYear);
    }
    showCupertinoModalPopupH(
        context: context,
        builder: (cxt) {
          String year = '${yearList[yearIndex]}';
          List<Widget> yearItemList = [];
          List<Widget> monthItemList = [];
          for (String data in yearList) {
            yearItemList.add(Text(data));
          }
          EdgeInsets padding = MediaQuery.of(context).padding;
          return RotatedBox(
            quarterTurns: 1,
            child: Container(
              margin: EdgeInsets.only(left: padding.top, right: padding.bottom),
              child: Column(
                children: [
                  Expanded(child: Container()),
                  Container(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        InkWell(
                          onTap: () => {
                            Navigator.pop(cxt),
                            onCancel(),
                          },
                          child: Container(
                            color: Colors.white,
                            padding: const EdgeInsets.only(
                                top: 5, left: 15, bottom: 5, right: 5),
                            child: const Text(
                              '取消',
                              style:
                                  TextStyle(color: Colors.black, fontSize: 18),
                            ),
                          ),
                        ),
                        InkWell(
                          onTap: () => {
                            Navigator.pop(cxt),
                            onConfirm(year),
                          },
                          child: Container(
                            color: Colors.white,
                            padding: const EdgeInsets.only(
                                top: 5, left: 5, bottom: 5, right: 15),
                            child: const Text(
                              '确定',
                              style:
                                  TextStyle(color: Colors.black, fontSize: 18),
                            ),
                          ),
                        ),
                      ],
                    ),
                    color: Colors.white,
                  ),
                  SizedBox(
                    height: 200,
                    child: CupertinoPicker(
                      scrollController:
                          FixedExtentScrollController(initialItem: yearIndex),
                      backgroundColor: Colors.white, //选择器背景色
                      itemExtent: 30, //item的高度
                      onSelectedItemChanged: (index) {
                        year = yearList[index];
                      },
                      children: yearItemList,
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }

  /// searchMap选择器-横向
  static pickerSearchMapH(
      BuildContext context, List<dynamic> dataList, String name,
      {required Function onConfirm, required Function onCancel}) {
    if (dataList.isEmpty) {
      '没有数据'.toString().toast();
      return;
    }
    showCupertinoModalPopupH(
        context: context,
        builder: (cxt) {
          Map confirmData = dataList[0];
          int mIndex = 0;
          List<dynamic> tempList = [];
          for (Map data in dataList) {
            tempList.add(data);
          }
          EdgeInsets padding = MediaQuery.of(context).padding;
          return RotatedBox(
            quarterTurns: 1,
            child: Container(
              margin: EdgeInsets.only(left: padding.top, right: padding.bottom),
              child: StatefulBuilder(
                builder: (context, state) {
                  return Column(
                    children: [
                      Expanded(child: Container()),
                      Container(
                        padding: const EdgeInsets.only(left: 10, right: 10),
                        color: Colors.white,
                        child: Stack(
                          alignment: Alignment.center,
                          children: [
                            Positioned(
                              child: Container(
                                height: 40,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                                  borderRadius: const BorderRadius.all(
                                      Radius.circular(100)),
                                  //设置四周边框
                                  border:
                                      Border.all(width: 1, color: Colors.black),
                                ),
                              ),
                            ),
                            Positioned(
                              child: Row(
                                children: [
                                  Expanded(
                                    child: Container(
                                      padding: const EdgeInsets.only(
                                          left: 10, top: 5),
                                      height: 60,
                                      child: TextField(
                                        decoration: const InputDecoration(
                                          border: InputBorder.none,
                                          hintText: "请输入关键词",
                                          hintStyle: TextStyle(
                                            color: Color(0x66333333),
                                            fontSize: 14,
                                          ),
                                        ),
                                        onChanged: (text) {
                                          state(() {
                                            tempList.clear();
                                            if (text.isEmpty) {
                                              for (Map data in dataList) {
                                                tempList.add(data);
                                              }
                                            } else {
                                              for (Map data in dataList) {
                                                if (data[name].contains(text)) {
                                                  tempList.add(data);
                                                }
                                              }
                                            }
                                          });
                                        },
                                      ),
                                    ),
                                  ),
                                  Container(width: 10),
                                  InkWell(
                                    onTap: () {},
                                    child: const Icon(Icons.search_outlined),
                                  ),
                                  Container(width: 10),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        color: Colors.white,
                        height: 200,
                        child: MediaQuery.removePadding(
                          context: context,
                          removeTop: true,
                          child: ListView.separated(
                            itemCount: tempList.length,
                            itemBuilder: (BuildContext context, int index) {
                              return InkWell(
                                child: Container(
                                  alignment: Alignment.center,
                                  padding: const EdgeInsets.all(5),
                                  child: Text(
                                    tempList[index][name],
                                    style: const TextStyle(
                                        color: Colors.black, fontSize: 18),
                                  ),
                                ),
                                onTap: () {
                                  Navigator.pop(cxt);
                                  mIndex = index;
                                  confirmData = tempList[index];
                                  onConfirm(confirmData, mIndex);
                                },
                              );
                            },
                            separatorBuilder:
                                (BuildContext context, int index) {
                              return const Divider(
                                  height: 1, color: Color(0x33000000));
                            },
                          ),
                        ),
                      ),
                    ],
                  );
                },
              ),
            ),
          );
        });
  }

  /// Map选择器多选-横向
  static pickerCheckMapH(
      BuildContext context, List dataList, String name, String checkName,
      {required Function onConfirm, required Function onCancel}) {
    if (dataList.isEmpty) {
      '没有数据'.toString().toast();
      return;
    }
    showCupertinoModalPopupH(
        context: context,
        builder: (cxt) {
          EdgeInsets padding = MediaQuery.of(context).padding;
          return RotatedBox(
            quarterTurns: 1,
            child: Container(
              margin: EdgeInsets.only(left: padding.top, right: padding.bottom),
              child: StatefulBuilder(
                builder: (context, state) {
                  return Column(
                    children: [
                      Expanded(child: Container()),
                      Container(
                        color: Colors.white,
                        height: 200,
                        child: MediaQuery.removePadding(
                          context: context,
                          removeTop: true,
                          child: ListView.separated(
                            itemCount: dataList.length,
                            itemBuilder: (BuildContext context, int index) {
                              return InkWell(
                                child: Container(
                                    alignment: Alignment.center,
                                    padding: const EdgeInsets.all(5),
                                    child: Row(
                                      children: [
                                        Icon(dataList[index][checkName] ==
                                                'true'
                                            ? Icons.check_box
                                            : Icons.check_box_outline_blank),
                                        Expanded(
                                          child: Text(
                                            dataList[index][name],
                                            textAlign: TextAlign.center,
                                            style: const TextStyle(
                                                color: Colors.black,
                                                fontSize: 18),
                                          ),
                                        ),
                                      ],
                                    )),
                                onTap: () {
                                  state(() {
                                    if (dataList[index][checkName] == 'true') {
                                      dataList[index][checkName] = 'false';
                                    } else {
                                      dataList[index][checkName] = 'true';
                                    }
                                  });
                                  List checkNameList = [];
                                  List checkDataList = [];
                                  for (Map data in dataList) {
                                    if (data[checkName] == 'true') {
                                      checkNameList.add(data[name]);
                                      checkDataList.add(data);
                                    }
                                  }
                                  onConfirm(
                                      checkDataList,
                                      checkNameList
                                          .toString()
                                          .replaceAll('[', '')
                                          .replaceAll(']', ''));
                                },
                              );
                            },
                            separatorBuilder:
                                (BuildContext context, int index) {
                              return const Divider(
                                  height: 1, color: Color(0x33000000));
                            },
                          ),
                        ),
                      ),
                    ],
                  );
                },
              ),
            ),
          );
        });
  }

  /// Map选择器
  static pickerMapMore(
      BuildContext context, List<dynamic> dataList, String name,
      {int initialItem = 0,
      String children = 'children',
      double itemPickerWidth = 150,
      bool isSelectDetail = true,
      String? titleText,
      Color? titleTextColor,
      required Function(List selectList, Map selectData) onConfirm,
      required Function onCancel}) {
    if (dataList.isEmpty) {
      '没有数据'.toString().toast();
      return;
    }

    showCupertinoModalPopup(
        context: context,
        builder: (cxt) {
          return MapPickerMore(
              dataList,
              name,
              children,
              itemPickerWidth,
              onConfirm,
              onCancel,
              MediaQuery.of(context).orientation == Orientation.landscape,
              isSelectDetail,
              titleText,
              titleTextColor);
        });
  }
}
